//
//  ViewController.m
//  webservice
//
//  Created by lanyun on 16/3/30.
//  Copyright © 2016年 lanyun. All rights reserved.
//

#import "ViewController.h"
#import "SoapUtil.h"
#import "GDataXMLNode.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:@"01" forKey:@"DeptCode"];
    [params setObject:@"01" forKey:@"Dept"];
    [SoapUtil SOAP:@"http://tempuri.org/" endpoint:@"http://192.168.1.131:808/Project1.dll/soap/ISampleService" action:NO method:@"GetDeptInfo" parameters:params progress:nil success:^(NSURLSessionDataTask *task, id  _Nullable responseObject) {
//        NSString *str = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
//        NSLog(@"%@", str);
        NSError *error;
        GDataXMLDocument *document = [[GDataXMLDocument alloc] initWithData:responseObject options:0 error:&error];
        GDataXMLElement *rootElement = document.rootElement;
        GDataXMLElement *soapBody=[[rootElement elementsForName : @"SOAP-ENV:Body" ] objectAtIndex :0];
        GDataXMLElement *getTypeResponse=[[soapBody elementsForName : @"NS1:GetDeptInfoResponse" ] objectAtIndex : 0 ];
        NSString *result = [[[getTypeResponse elementsForName : @"return" ] objectAtIndex : 0 ] stringValue];
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:[result dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@", [dic objectForKey:@"data"]);
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError *error) {
        NSLog(@"%ld", (long)[error code]);
    }];
}

- (IBAction)btn:(UIButton *)sender {
    
    

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
